package br.unirio.parser;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class ParseMusica {
	
	
	public static void main(String[] args) throws Exception {
		
		
		BufferedReader reader = new BufferedReader(new FileReader("src/br/unirio/parser/musicas.txt"));
		BufferedWriter writer = new BufferedWriter(new FileWriter("src/br/unirio/parser/script-musicas.txt"));
		String linha = reader.readLine();
		String[] parametros = null;
		int i = 1;
		int ultimoArtista = Integer.valueOf(linha.split("#")[1]);
		
		while(linha != null)
		{
			parametros = linha.split("#");
			if(ultimoArtista == Integer.valueOf(parametros[1])){
				writer.append("insert into Musica(ID, IDAlbum, Nome, Ordem) values ("+parametros[0]+ ", "+parametros[1]+", \""+parametros[2]+"\" , "+i+" );  \n");
				System.out.println("insert into Musica(ID, IDAlbum, Nome, Ordem) values ("+parametros[0]+ ", "+parametros[1]+", \""+parametros[2]+"\" , "+i+" );  \n");
				i++;
			}else{
				i=1;
				ultimoArtista = Integer.valueOf(parametros[1]);
				writer.append("insert into Musica(ID, IDAlbum, Nome, Ordem) values ("+parametros[0]+ ", "+parametros[1]+", \""+parametros[2]+"\" , "+i+" );  \n");
				System.out.println("insert into Musica(ID, IDAlbum, Nome, Ordem) values ("+parametros[0]+ ", "+parametros[1]+", \""+parametros[2]+"\" , "+i+" );  \n");
			}
			linha = reader.readLine();
		}
		writer.flush();
}
	}

